<template>
  <div>
    <el-row style="margin-bottom:10px;display:flex;justify-content:flex-start">
      <el-input
        placeholder="人员姓名"
        style="width:20%;margin-right:20px"
        v-model="statusData.hash.username"
        clearable
      ></el-input>
      <el-input
        placeholder="证书名称"
        style="width:20%;margin-right:20px"
        v-model="statusData.hash.cername"
        clearable
      ></el-input>
      <el-input
        placeholder="证书编号"
        style="width:20%;margin-right:20px"
        v-model="statusData.hash.cernum"
        clearable
      ></el-input>
      <el-input placeholder="专业类别" style="width:20%;" v-model="statusData.hash.majortype" clearable></el-input>
      <!-- <el-date-picker
        v-model="statusData.hash.grantime"
        style="margin-left:25px;"
        type="daterange"
        rangeSeparator="至"
        startPlaceholder="开始日期"
        endPlaceholder="结束日期"
        valueFormat="yyyy-MM-dd"
      >
      </el-date-picker>-->
      <el-date-picker
        v-model="statusData.hash.validtime"
        style="margin:0 20px;"
        type="daterange"
        rangeSeparator="至"
        startPlaceholder="截止日期始"
        endPlaceholder="截止日期止"
        valueFormat="yyyy-MM-dd"
      ></el-date-picker>
      <el-button size="mini" type="primary" @click="getstatuslist">搜索</el-button>
    </el-row>
    <el-row>
      <el-button size="mini" @click="showaddstatus">添加资格</el-button>
      <el-button size="mini" type="primary" @click="amandstatus">编辑</el-button>
      <el-button size="mini" type="success" @click="deletestatus">删除</el-button>
    </el-row>
    <el-divider></el-divider>
    <statustable
      :tableData="statuslist"
      @itemvals="itemvals"
      :pagobj.sync="pagobj"
      :ischeck="false"
      id="tableExcel"
    ></statustable>
    <addstatus v-if="isaddstatus" :itemvalname="itemvalname" :chousebtn="btnvalue"></addstatus>
  </div>
</template>

<script>
import addstatus from '~/components/person/jobstatus/addstatus.vue';
import statustable from '~/components/person/jobstatus/statustable.vue';
import FileSaver from 'file-saver';
import XLSX from 'xlsx';

export default {
  data() {
    return {
      dialogVisible: false,
      ts: this.newStore(),

      statusData: {
        cols: [],
        hash: {
          username: '',
          cername: '',
          cernum: '',
          grantime: '',
          validtime: [],
          majortype: '',
          pid: '',
          id: '',
        },
      },
      // entrttimearr:[],
      pagesize: 0,
      currentPage: 0,
      pagobj: {
        // 分页
        currentPage3: 1,
        pagesize: 10,
        total: 10,
      },
      statusidarr: [], // 删除所用的数组id
      isaddstatus: false, // 添加弹窗
      // isaddstatus2: false, //编辑弹窗
      btnvalue: 0,
      Object: '',
      itemval: {}, // 编辑传回来的d对象
      cername: '',
      changelist: '',
      statuslist: [],
      // itemdata:[], //项目类型
      changelistper: {},
    };
  },
  components: {
    addstatus,
    statustable,
  },
  watch: {
    // Object() {
    //   this.getlaborlist();
    // },
    changelistper() {
      this.getstatuslist();
    },
  },
  created() {
    this.getstatuslist();
  },
  methods: {
    // 删除职业资格
    deletestatus() {
      // console.log(this.statusidarr, "0");
      if (this.statusidarr.length > 1) {
        this.$confirm('是否批量删除职业资格信息?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          const req = {
            handle:
              '1CB43CC1631B5D5B8DDD57687CDE4AC73F156CD5A96D26B9F8B82A84C4C3C33D',
            id: this.statusidarr,
          };
          this.spost(this.ts, '/mainservlet', req).then((ts) => {
            if (ts.d.sflag == 'success') {
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
              this.getstatuslist();
            }
          });
        });
      } else if (this.statusidarr.length == 1) {
        this.$confirm('是否删除该职业资格信息?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          const req = {
            handle:
              '1CB43CC1631B5D5B8DDD57687CDE4AC73F156CD5A96D26B9F8B82A84C4C3C33D',
            id: this.statusidarr,
          };
          this.spost(this.ts, '/mainservlet', req).then((ts) => {
            if (ts.d.sflag == 'success') {
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
              this.getstatuslist();
            }
          });
        });
      } else {
        this.$alert('请选择职业资格', '提示');
      }
    },
    // 编辑职业资格
    amandstatus() {
      (this.dialogVisible = true), (this.btnvalue = 2);
      if (Object.keys(this.itemval).length == 1) {
        let itemvals = {};
        itemvals = this.itemval[0];
        this.itemvalname = itemvals;
        this.reload('isaddstatus');
      } else {
        this.$alert('编辑只能编辑一个', '提示');
      }
    },
    // table 传给父组件
    itemvals(val) {
      // console.log(val, "wwwwww");
      this.itemval = val;
      this.statusidarr = [];
      for (let i = 0; i < this.itemval.length; i++) {
        this.statusidarr.push(this.itemval[i].hash.id);
      }
      // console.log(this.statusidarr, "23");
    },
    // 监听子组件的(添加)
    addstatus(val) {
      this.Object = {};
      this.Object = val;
      // val.hash.holder = val.hash.holders;
      // console.log(val, "22223322");
      // this.carlist.unshift(val);
      // console.log(this.statuslist, "66666");
    },
    // 公共组件刷新
    reload(partsname) {
      // console.log(partsname);
      this[partsname] = false;
      this.$nextTick(() => {
        this[partsname] = true;
      });
    },
    // 点击添加职业资格信息
    showaddstatus() {
      (this.dialogVisible = true), (this.btnvalue = 1);
      this.reload('isaddstatus');
    },
    // 分页
    handleCurrentChange() {
      this.getstatuslist();
    },
    // 获取列表
    getstatuslist() {
      console.log('2222');
      const req = {
        handle:
          '1CB43CC1631B5D5B8DDD57687CDE4AC73F156CD5A96D26B9CD3A43E9777C4E90',
        username: this.statusData.hash.username,
        cername: this.statusData.hash.cername,
        cernum: this.statusData.hash.cernum,
        validtime1: this.statusData.hash.validtime[0],
        validtime2: this.statusData.hash.validtime[0],
        // grantime: this.entrttimearr[0],
        // validtime: this.entrttimearr[1],
        majortype: this.statusData.hash.majortype,
        id: this.statusData.hash.id,
        start: (this.pagobj.currentPage3 - 1) * this.pagobj.pagesize,
        limit: this.pagobj.pagesize,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.statuslist = ts.d.data.operation1;
        this.pagobj.total = parseInt(ts.d.data.operation2[0].hash.allrs);
        // console.log(this.statuslist,'789')
      });
    }
  },
};
</script>

